/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.zb.hms.global.controller;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.servlet.KaptchaExtend;
import com.google.code.kaptcha.util.Config;
import com.google.code.kaptcha.util.Configurable;
import com.zb.hms.base.util.messageUtil.ResultMessage;
import com.zb.hms.business.web.exception.resolver.CustomMappingExceptionResolver;

import java.awt.Font;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Properties;
import java.util.logging.Level;

import javax.activation.MimetypesFileTypeMap;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @Description 
 * @author zb
 * @datetime 2017-7-30 14:15:55
 * @version V1.0
 */
@SuppressWarnings(value = {"unused"})
@Controller
public class GlobalController {
    private static final Logger LOG = Logger.getLogger(GlobalController.class);
    @Resource
    private DefaultKaptcha kaptcha;
    @Resource
    private ResultMessage resultMessage;
    //输出验证码
    @RequestMapping(value = "/Pubverify-code/{id}",produces={"image/png"})
    @ResponseBody
    public BufferedImage  verify(HttpSession session) {	
        String text = kaptcha.createText();
        BufferedImage image = kaptcha.createImage(text);            
        session.setAttribute(kaptcha.getConfig().getSessionKey(), text);		
        session.setAttribute(kaptcha.getConfig().getSessionDate(), new Date());
        return  image;
    }
}
